package cn.lastcrdg.testitemdecoration;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * author：liluo
 * e-mail：lastcrazysun@163.com
 * company：cusc
 * date：2018/4/8 15:05
 * description：
 */
public class MyAdapter extends RecyclerView.Adapter<MyViewHolder>{

    private Context mContext;
    private List<MovieBean.SubjectsBean> mMovieBeans;

    public MyAdapter(Context context, List<MovieBean.SubjectsBean> movieBeans) {
        mContext = context;
        mMovieBeans = movieBeans;
    }

    public void setMovieBeans(List<MovieBean.SubjectsBean> movieBeans) {
        mMovieBeans = movieBeans;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_item, null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        MovieBean.SubjectsBean subjectsBean = mMovieBeans.get(position);
        holder.mTv.setText(subjectsBean.getTitle());
        Picasso.get().load(subjectsBean.getImages().getMedium()).into(holder.mIv);
    }

    @Override
    public int getItemCount() {
        return mMovieBeans == null ? 0 : mMovieBeans.size();
    }
}
